package com.jqd.framework.core.hessian.exception;

import java.util.Map;

import org.springframework.core.style.StylerUtils;

import com.jqd.framework.core.hessian.model.ServiceRequest;

public class NoSuchHandlingMethodException extends Exception {
	
	private static final long serialVersionUID = 1L;
	
	private String methodName;
	
	
	/**
	 * Create a new NoSuchRequestHandlingMethodException for the given request.
	 * 
	 * @param request
	 *            the offending HTTP request
	 */
	public NoSuchHandlingMethodException(ServiceRequest request) {
		this(request.getRequestedActionID(), request.getParameters());
	}
	
	
	/**
	 * Create a new NoSuchRequestHandlingMethodException.
	 * 
	 * @param urlPath
	 *            the request URI that has been used for handler lookup
	 * @param method
	 *            the HTTP request method of the request
	 * @param parameterMap
	 *            the request's parameters as map
	 */
	public NoSuchHandlingMethodException(String actionID, Map<?, ?> parameterMap) {
		super("No matching handler method found for action request: path '" + actionID
				+ "', parameters " + StylerUtils.style(parameterMap));
	}
	
	
	/**
	 * Create a new NoSuchRequestHandlingMethodException for the given request.
	 * 
	 * @param methodName
	 *            the name of the handler method that wasn't found
	 * @param controllerClass
	 *            the class the handler method was expected to be in
	 */
	public NoSuchHandlingMethodException(String methodName, Class<?> actionClass) {
		super("No request handling method with name '" + methodName + "' in class ["
				+ actionClass.getName() + "]");
		this.methodName = methodName;
	}
	
	
	/**
	 * Return the name of the offending method, if known.
	 */
	public String getMethodName() {
		return this.methodName;
	}
	
}
